<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>物品统计-详情</title>
<meta name="decorator" content="default" />
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${ctxStatic}/easyui/demo/demo.css">
<script type="text/javascript" src="${ctxStatic}/easyui/jquery.min.js"></script>
<script type="text/javascript"
	src="${ctxStatic}/easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<div style="margin-bottom: 5px;">
		<!-- 物件：<input class="easyui-combotree" data-options="" style="width: 300px;" id="cc" /> -->
		物件：<select id="datag" class="easyui-combogrid" style="width:30%" data-options="
				panelWidth: 500,
				panelMinWidth: '50%',
				idField: 'gid',
				textField: 'gname',
				method: 'get',
				mode : 'remote',
				columns: [[
					{field:'gid',title:'物件编号',width:60},
					{field:'gname',title:'物件名称',width:150},
					{field:'series',title:'物件系列',width:40,align:'left'}
				]],
				onLoadSuccess:function(data){
					var value=$('#datag').combogrid('getValue');
					if(1==data.rows.length&&data.rows[0].gid==value){
						value=' '+value;
					}
					$('#datag').combogrid('setValue', value);
					
				},
				onSelect:function(recordidex,rowData){
                },
               keyHandler:{ 
                   query:function(q){
                   		if(q.length>=9){
	                   		q=q.trim();
	                   		quickDimQuery(q);
	                   	}
                   }
               },
				fitColumns: true
			">
			</select>
		开始时间：<input class="easyui-datetimebox" id="startTime" value="" style="width:200px">
		结束时间：<input class="easyui-datetimebox" id="endTime" value="" style="width:200px">
	</div>
	<div>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="sub('0');">今天</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="sub('7');">最近一星期</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="sub('30');">最近一月</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="sub('');">提交</a>
	</div>
	<br>
	<table id="dg" title="物品统计"
		style="width: 100%; height: auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				showFooter: true">
		<thead>
			<tr>
				<th data-options="field:'execDate',width:200,align:'center'">执行时间</th>
				<th data-options="field:'oCode',width:200,align:'center'">单号</th>
				<th data-options="field:'executorCode',width:100,align:'center'">执行人</th>
				<th data-options="field:'inAmount',width:100,align:'center'">入量</th>
				<th data-options="field:'outAmount',width:100,align:'center'">出量</th>
			</tr>
		</thead>
	</table>
	
	


	<script type="text/javascript">
		var initData='${typeId}';
		function sub(data){
			/* var cc=$("#cc").combotree('getValue'); */
			var cc=$("#datag").combogrid('getValue');
			var startTime=$("#startTime").datebox('getValue');
			var endTime=$("#endTime").datebox('getValue');
			console.log(cc);
			if(null!=data&&""!=data){
				startTime='';
				endTime='';
			}
			if(null==cc||""==cc){
				$.messager.alert('提示','请选择物件','info');
				return;
			}
			console.log(data+":"+startTime+":"+endTime)
			if(''==data&&startTime==''&&endTime==''){
				$.messager.alert('提示','缺少时间参数','info');
				return;
			}
			_list={};
			_list={'code':cc,
					'approvalDate':data,
					'startTime':startTime,
					'endTime':endTime};
			$.ajax({
			    url: '${ctx}/erp/goodsType/goodsStatistics',         
			    data: _list,
			    dataType: "json",
			    type: "POST",          
			    success: function (data) {
			    	console.log(data);
			    	$('#dg').datagrid({
						data : data
					});
			    }
			});
		}
		function getData() {
			var rows=[];
			for(var i=0;i<5;i++){
				rows.push({
					oCode :'',
					executorCode : '',
					execDate : '',
					outAmount : '',
					inAmount :''
				});
			} 
			return rows;
		}
		/* $(function(){
			$('#cc').combotree ({
				url:"${ctx}/erp/goodsType/queryLinkGoods?typeId=${typeId}",
				state:close,
				onLoadSuccess: function (node, data) {
				},
				onBeforeExpand:function(node) {
		      		$('#cc').combotree("tree").tree("options").url = "${ctx}/erp/goodsType/queryLinkGoods?sonTypeId=" + node.id;
				},
				onSelect : function(node) {  
			        //返回树对象  
			        var tree = $(this).tree;  
			        //选中的节点是否为叶子节点,如果不是叶子节点,清除选中  
			        var isLeaf = tree('isLeaf', node.target);  
			        if (!isLeaf) {  
			            //清除选中  
			            $('#cc').combotree('clear');  
			        }  
			    }
			});
			//空白表格初始化
			$('#dg').datagrid({
				data : getData()
			});
		}); */
		
		$(function(){
			$('#dg').datagrid({
				data : getData()
			});
		})
		function quickDimQuery(q){
			q=q.trim();
			var url = 'dimQueryLinkGoods';
			
			$("#datag").combogrid('grid').datagrid('options').url= url+"?key="+q+"&cssb="+initData;
            $("#datag").combogrid('grid').datagrid('load', { 'keyword': q });
            
            $("#datag").combogrid('setValue', q);
            
		}
	</script>
</body>
</html>